package comc.springbatch;



import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.support.CompositeItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

//多种Process处理
@Configuration
public class MyJob implements JobExecutionListener {
    @Autowired
    public JobBuilderFactory jobBuilderFactory;
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
    @Autowired
    public DbWriter dbWriter;
    @Autowired
    public DbReader myReader2;

    @Bean
    public Job job4() {
        return jobBuilderFactory.get("j5r2")
                .start(step4()).listener(this).build();
    }
    Map<String, JobParameter> parameters;
    @Bean
    public Step step4() {
        return stepBuilderFactory.get("054").
                chunk(5)
                .faultTolerant()
                .listener(this)
                .reader(myReader2.myReader2())
                .writer(dbWriter)
                .build();
    }


    @Override
    public void beforeJob(JobExecution jobExecution) {

        parameters = jobExecution.getJobParameters().getParameters();
        System.out.println("获取的的参数"+parameters.get("msg").getValue());
    }

    @Override
    public void afterJob(JobExecution jobExecution) {

    }
}
